package com.android.launcher3;

import android.graphics.Rect;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;

public class TFAnimateEngine {

	public static final String LOG_TAG = "TFAnimateEngine";

	private Interpolator mInterpolator;
	private static final Interpolator DEFAULT_INTERPOLATOR = new LinearInterpolator();

	/**
	 * Creates a new TFAnimateEngine object.
	 */
	public TFAnimateEngine() {
		this.mInterpolator = DEFAULT_INTERPOLATOR;
	}

	public Rect[] getRect(final Rect[] startRects, final Rect[] finishRects,
			final Rect[] paramArrayOfRect3, float paramFloat) {
		if ((startRects == null) || (finishRects == null)) {
			return null;
		}

		int i = startRects.length;

		int j = finishRects.length;

		if (i != j) {
			return null;
		}

		// 必须在0和1之间.
		float f1 = Math.min(1.0F, paramFloat);
		paramFloat = Math.max(0.0F, f1);

		int k = startRects.length;
		Rect[] returnRects;

		if ((paramArrayOfRect3 == null) || (paramArrayOfRect3.length != k)) {
			returnRects = new Rect[k];
		} else {
			returnRects = paramArrayOfRect3;
		}

		float f2 = this.mInterpolator.getInterpolation(paramFloat);

		int m = 0;

		while (m < k) {
			if (returnRects[m] == null) {
				returnRects[m] = new Rect();
			}

			returnRects[m].left = startRects[m].left
					+ (int) ((finishRects[m].left - startRects[m].left) * f2);

			returnRects[m].right = startRects[m].right
					+ (int) ((finishRects[m].right - startRects[m].right) * f2);

			returnRects[m].top = startRects[m].top
					+ (int) ((finishRects[m].top - startRects[m].top) * f2);

			returnRects[m].bottom = startRects[m].bottom
					+ (int) ((finishRects[m].bottom - startRects[m].bottom) * f2);

			m++;
		}

		return returnRects;
	}

	public void setInterpolator(Interpolator paramInterpolator) {
		if (paramInterpolator == null) {
			paramInterpolator = DEFAULT_INTERPOLATOR;
		}
		this.mInterpolator = paramInterpolator;
	}
}
